<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN""http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">

<html xmlns="http://www.w3.org/1999/xhtml">
<head>
    <title>Fit Layout</title>
    <meta content="text/html; charset=UTF-8" http-equiv="content-type"/>
    <script src="../../../../scripts/jquery.min.js"></script>
    <script src="../../../../scripts/miniui/miniui.js"></script>
    <link href="../../../../scripts/miniui/themes/default/miniui.css" rel="stylesheet">
    <link href="../../../../scripts/miniui/themes/icons.css" rel="stylesheet">
    <link href="../../../../scripts/miniui/themes/pure/skin.css" rel="stylesheet">
    <script src="../../../../scripts/core.js"></script>

</head>
<body>
<style type="text/css">
    html, body {
        margin: 0;
        padding: 0;
        border: 0;
        width: 100%;
        height: 100%;
        overflow: hidden;
    }
</style>
<mini-toolbar style="width:100%;border-bottom:0;padding:0px;">
    <table style="width:100%;">
        <tr>
            <td style="width:100%;">
                <a class="mini-button" iconCls="icon-add" onclick="lock()" plain="true" tooltip="封号...">封号</a>
                <a class="mini-button" iconCls="icon-remove" onclick="unlock()" plain="true">解封</a>
                <a class="mini-button" iconCls="icon-unlock" onclick="downRank()" plain="true">踢下排行榜</a>
                <a class="mini-button" iconCls="icon-sort" onclick="canRank()" plain="true">上排行榜</a>
            </td>

        </tr>
        <tr>
            <td>
                注册时间从<input class="mini-datepicker" id="start"/>到
                <input class="mini-datepicker" id="end"/>
            </td>
            <td style="white-space:nowrap;">
                <input class="mini-textbox" emptyText="关键字" id="key" onenter="onKeyEnter" style="width:150px;"/>
                <a class="mini-button" onclick="search()">查询</a>
            </td>
        </tr>
    </table>
</mini-toolbar>
<!--撑满页面-->
<div class="mini-fit">

    <mini-datagrid _dataField="data111" allowCellEdit="true" allowCellSelect="true"
                   allowResize="true"
                   allowSortColumn="false" class="mini-datagrid"
                   id="datagrid1"
                   idField="id" multiSelect="false"
                   pageSize="60" showSortIcon="true"
                   sizeList="[20,30,50,100,500,7000]"
                   style="width:100%;height:100%;"
                   url="/role/pageRole"
    >
        <columns>
            <column type="indexcolumn"></column>
            <column field="accountId" width="100">账号id
            </column>
            <column field="roleId" name="roleId" width="150">角色id
            </column>
            <column field="nick" width="100">昵称
            </column>
            <column field="createAt" width="180">注册时间
            </column>
            <column field="lastOfflineTime" width="180">最后离线时间
            </column>

            <column field="level" width="50">等级

            </column>

            <column field="exp" width="100">经验
            </column>

            <column field="ban" width="50">封号
            </column>
            <column field="banTime" width="180">封号时间
            </column>
            <column field="banApplyTime" width="180">封号有效期
            </column>

            <column field="ip" width="100">Ip
            </column>
            <column field="openId" width="100">openId
            </column>
        </columns>
    </mini-datagrid>

</div>

<script type="text/javascript">

    var auth = GetParams()
    mini.parse();


    var grid = mini.get("datagrid1");
    grid.setAjaxOptions({
        headers: {"userId": auth.userId, "token": auth.token}
    });

    grid.load();


    async function lock() {
        if (grid.getSelecteds().length == 0) return;
        var row = grid.getSelecteds()[0];

        mini.open({
            targetWindow: window,
            url: "Lock.html?authId=" + auth.authId + "&token=" + auth.token + "&targetUserId=" + row.accountId,
            title: "新增",
            width: 1024,
            height: 800,
            onload: function () {

            },
            ondestroy: function (action) {

            }
        });
    }

    function exportData() {
        mini.mask({
            el: document.body,
            cls: 'mini-mask-loading',
            html: '加载中...'
        });
        var key = mini.get("key").getValue();
        var obj = mini.get("adChannel");
        var order = mini.get("orderType");
        var recharge = mini.get("chargeType");
        var sizeType = mini.get("sizeType").getValue();

        var start = mini.get("start").getValue();
        var end = mini.get("end").getValue();
        $.ajax({
            url: "/cmsapi/business/getAllUserInfo",
            data: mini.encode({
                targetUserId: key,
                adChannel: obj.getValue(),
                orderType: order.getValue(),
                charge: recharge.getValue(),
                startTime: start === "" ? null : start.toISOString(),
                endTime: end === "" ? null : end.toISOString(),
                pageIndex: 0,
                pageSize: sizeType
            }),
            type: "post",
            headers: {"userId": auth.userId, "token": auth.token},
            contentType: 'application/json',
            success: function (text) {
                var resp = mini.decode(text);
                gridToCSV(grid, resp.data, "用户数据")
                mini.unmask(document.body);
            },
            error: function (jqXHR, textStatus, errorThrown) {
                alert(jqXHR.responseText);
            }
        });

    }


    function unlock() {
        if (grid.getSelecteds().length == 0) return;
        var row = grid.getSelecteds()[0];

        $.ajax({
            url: "/auth/unBan",
            data: mini.encode({
                "accountId": row.accountId
            }),
            type: "post",
            headers: {"authId": auth.authId, "token": auth.token},
            contentType: 'application/json',
            success: function (text) {
                grid.reload();
                var resp = mini.decode(text);
                if (resp.code == 200) {
                    mini.alert("解封成功")
                }
            },
            error: function (jqXHR, textStatus, errorThrown) {
                alert(jqXHR.responseText);
            }
        });
    }


    function downRank() {
        if (grid.getSelecteds().length == 0) return;
        var row = grid.getSelecteds()[0];

        $.ajax({
            url: "/rank/DownRank",
            data: mini.encode({
                "roleId": row.roleId
            }),
            type: "post",
            headers: {"userId": auth.userId, "token": auth.token},
            contentType: 'application/json',
            success: function (text) {
                grid.reload();
                var resp = mini.decode(text);
                if (resp.code == 200) {
                    mini.alert("成功下排行榜")
                }
            },
            error: function (jqXHR, textStatus, errorThrown) {
                alert(jqXHR.responseText);
            }
        });
    }


    function canRank() {
        if (grid.getSelecteds().length == 0) return;
        var row = grid.getSelecteds()[0];

        $.ajax({
            url: "/rank/UpRank",
            data: mini.encode({
                "roleId": row.roleId
            }),
            type: "post",
            headers: {"userId": auth.userId, "token": auth.token},
            contentType: 'application/json',
            success: function (text) {
                grid.reload();
                var resp = mini.decode(text);
                if (resp.code == 200) {
                    mini.alert("成功上排行榜")
                }
            },
            error: function (jqXHR, textStatus, errorThrown) {
                alert(jqXHR.responseText);
            }
        });
    }


    function search() {
        var key = mini.get("key").getValue();
        var start = mini.get("start");
        var end = mini.get("end");
        var param = {}
        if (key != "") {
            param.roleId = key;
        }
        if (start.getValue() != "") {
            param.startTime = mini.formatDate(start.getValue(), "yyyy-MM-dd");
        }
        if (end.getValue() != "") {
            param.endTime = mini.formatDate(end.getValue(), "yyyy-MM-dd")
        }
        grid.load(param);
    }


</script>

</body>
</html>